﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Diagnostics;

namespace Fulcrum.ControlGenerator
{
    public class RoutedCommandBindingDataContext
    {
        public RoutedCommandBindingDataContext(IRoutedCommandBindingConfiguration routedCommandBindingConfig, string typeName)
        {
            ConfigureContext(routedCommandBindingConfig);

            this.OwningType = typeName;
            this.CommandName = String.Format("{0}Command", this.Name);

            Debug.Assert(this.OwningType != null);
        }

        public RoutedCommandBindingDataContext(IRoutedCommandBindingConfiguration routedCommandBindingConfig)
        {
            ConfigureContext(routedCommandBindingConfig);
            this.CommandName = this.Name;
            Debug.Assert(this.OwningType != null);
        }

        private void ConfigureContext(IRoutedCommandBindingConfiguration routedCommandBindingConfig)
        {
            this.CanExecuteAlways = routedCommandBindingConfig.CanExecuteAlways;
            this.Name = routedCommandBindingConfig.Name;
            this.OwningType = routedCommandBindingConfig.OwningType;
            this.Summary = routedCommandBindingConfig.Summary;
        }


        public string Name
        {
            get;
            private set;
        }

        public string OwningType
        {
            get;
            private set;
        }

        public string Summary
        {
            get;
            private set;
        }

        public bool CanExecuteAlways
        {
            get;
            private set;
        }

        public string CommandName
        {
            get;
            private set;
        }

        public string StaticCanExecuteMethodName
        {
            get
            {
                Debug.Assert(false == this.CanExecuteAlways);
                return String.Format("{0}_CommandCanExecute", this.CommandName);
            }
        }

        public string CanExecuteMethodName
        {
            get
            {
                Debug.Assert(false == this.CanExecuteAlways);
                return String.Format("On{0}CanExecute", this.Name);
            }
        }

        public string StaticExecutedMethodName
        {
            get
            {
                return String.Format("{0}_CommandExecuted", this.CommandName);
            }
        }

        public string ExecutedMethodName
        {
            get
            {
                return String.Format("On{0}Executed", this.Name);
            }
        }
    }
}
